$(function () {
    $("#jqGrid").jqGrid({
        url: '../sys/house/list',
        datatype: "json",

        colModel: [			
			{ label: '房源编码', name: 'serialNum', index: "serialNum", width: 75 },
			{ label: '区域', name: 'districtName', index: "districtName", width: 80},
			{ label: '房源地址', name: 'address', index: "address", width: 80},
			{ label: '基本信息', name: 'basicMsg', index: "basicMsg", width: 80},
			{ label: '租金价格', name: 'rentalPrice', width: 80, formatter: function(value, options, row){
				if ("合租" == row.rentType && row.children && row.children.length > 0) {
					var totalRentalPrice = 0;
					for (var i=0; i<row.children.length; i++) {
						totalRentalPrice += row.children[i].rentalPrice*1;
					}
					return totalRentalPrice + '元';
				} else {
					return row.rentalPrice ? row.rentalPrice + '元' : '';
				}
	        }},
			{ label: '房东姓名', name: 'landlord.userName', index: "landlord_userName", width: 80},
			{ label: '房东电话', name: 'landlord.phone', index: "landlord_phone", width: 80},
			{ label: '租约状态', name: 'rentStatus', index: "rentStatus", width: 80},
			// { label: '审核状态', name: 'applyStatus', index: "applyStatus", width: 80},
			{ label: '操作', name: 'func', width: 80, formatter: function(value, options, row){
				return '<a class="layui-btn layui-btn-sm btn-detail" id="'+row.id+'">查看</a><a class="layui-btn layui-btn-sm btn-update" id="'+row.id+'">编辑</a>';
	        }}
        ],
        loadComplete: function (data) {
        	window.jsonData = data;

        	for (var i=0; i<data.page.list.length; i++) {
        		var row = data.page.list[i];
        		if (row.children && row.children.length > 0) {
        			$($('.ui-sgcollapsed')[i]).click();
        		}
        	}
        	
        },
		viewrecords: true,
		height: '100%',
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order:"order"
        },
        subGrid: true,
        subGridWidth: '0px',
        subGridOptions: {
            "plusicon"  : "",
            "minusicon" : "",
            "openicon"  : "",
        },
        subGridRowExpanded: function(subgrid_id, row_id) {
        	var objs;
        	if (jsonData.page.list) {
        		for (var i=0; i<jsonData.page.list.length; i++) {
        			if (jsonData.page.list[i].id == row_id) {
        				objs = jsonData.page.list[i];
        				break;
        			}
        		}
        	}

            var subgrid_table_id = subgrid_id+"_t";
            
            $("#"+subgrid_id).html('<div id="'+subgrid_table_id+'""></div>');

            var subgrid = $('<ul></ul>').addClass('roomlist');

            if (objs && objs.children && objs.children.length > 0) {

            	for (var i=0; i<objs.children.length; i++) {
	            	var item = $('<li class="room"></li>')
                        .append('<div class="rentStatus'+(objs.children[i].rentStatus === '空置'?' red"':' green"')+'>'+objs.children[i].rentStatus+'</div>')
	                  .append('<div class="room_title">房间'+objs.children[i].door+'</div>')
					  .append('<div>房源编码：'+(objs.children[i].serialNum || '')+'</div>')
	                  .append('<div>朝向：'+objs.children[i].direct+ '，面积：' + objs.children[i].buildingArea +'平</div>')
	                  .append('<div>租金：'+objs.children[i].rentalPrice+'元/月</div>')
	                  .append('<div>'+(objs.children[i].payMode||'')+'</div>')

            		subgrid.append(item);
            	}
            }
            $("#"+subgrid_table_id).append(subgrid);
        },
        beforeSelectRow: function() {
		    return false;
		},
		onRightClickRow: function () {
		    return false;
		},
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        	$('.ui-row-ltr').removeClass('success');

        	$('#jqGrid').off('contextmenu');

        	$('.btn-detail').on('click', function () {
				var id = $(this).attr('id');
				if(!id) { return; }
	            vm.detail(id)
        	});
        	$('.btn-update').on('click', function () {
				var id = $(this).attr('id');
				if(!id) { return; }
	            vm.update(id)
        	});

        	vm.q = {
        		districtName: '',
				rentType: '',
				serialNum: '',
				rentStatus: ''
        	};
        },
    });
});
var vm = new Vue({
		el:'#rrapp',
		data:{
			house_add_imgs: [],
			propright_add_imgs: [],
			q:{
				serialNum: null,
				districtName: "",
				rentType: "",
				rentStatus: "",
			},
			districtNames:[
				{name:"请选择区域", value:""},
				{name:"雄县", value:"雄县"},
				{name:"容城县", value:"容城县"},
				{name:"安新县", value:"安新县"}
				],
	        districts:[
	            {name:"雄县"},
	            {name:"容城县"},
	            {name:"安新县"}
	        ],
			rentTypes:[
				{name:"请选择出租方式", value:""},
				{name:"整租", value:"整租"},
				{name:"合租", value:"合租"}
				],
			rentStatuses:[
				{name:"请选择租约状态", value:""},
				{name:"空置", value:"空置"},
				{name:"部分出租", value:"部分出租"},
				{name:"已出租", value:"已出租"}
				],
	        hdstrs:[
				{name: '冰箱'},
				{name: '洗衣机'},
				{name: '热水器'},
				{name: '衣橱'},
				{name: '电视机'},
				{name: '空调'},
				{name: '微波炉'},
				{name: 'wifi'},
				{name: '床'},
				{name: '燃气灶'},
				{name: '沙发'},
				{name: '餐桌'},
				{name: '书桌'},
				{name: '椅子'},
				{name: '油烟机'}
	        ],
	        payModes:[
	            {name:"一月一付"},
	            {name:"两月一付"},
	            {name:"三月一付"},
	            {name:"六月一付"},
	            {name:"一年一付"}
	        ],
			showPanel: 'list',
			showlandlord: false,
			title:null,
			house:{
	            status:"1",
	            cityName:"雄安市",
	            districtName:"雄县",
				rentType:"整租",
				payMode:"一月一付"
			},
			userlandlord: {
				phone: '',
				userName: '',
				idCard: '',
				idAPath: '',
				idBPath: ''
			},
			orientation: [
	            {name:"东"},
	            {name:"南"},
	            {name:"西"},
	            {name:"北"},
	            {name:"东南"},
	            {name:"西南"},
	            {name:"东北"},
	            {name:"西北"}
			]
		},
		mounted: function () {
			this.$nextTick(function () {
				console.log('**** in mounted');
			})
		},
		methods: {
			query: function () {
				$("#jqGrid").jqGrid('setGridParam',{page: 1});
				vm.reload();
			},
			detail: function (id) {
				console.log('**** in detail, id: ', id);
				vm.userlandlord = {};
				if (!id) {return false;}
	            var url = "../sys/house/detail";
				$.ajax({
					type: 'GET',
				    url: url,
				    data: {houseId: id},
				    success: function(r){
	                    if(r.code == 0){
				            vm.house = r.entity;
				            var hdobj = $('.panel-detail .hardwares input[type="checkbox"]');
				            for (var i=0; i<hdobj.length; i++) {
				            	$(hdobj[i]).prop('checked', vm.house.hardware.indexOf( $(hdobj[i]).val() )>=0);
				            }
							imgup_at_detail(r.entity.houseImages);
							prop_at_detail(r.entity.houseAuthImages);
							apm_at_detail(r.entity.children);
							vm.showPanel = "detail";

							vm.showlandlord = true;
							vm.userlandlord = r.entity.landlord;
							var idacard, idbcard;
							idacard = new Uploader({
								at: $('.panel-detail #idACard'),
								value: vm.userlandlord.idAPath
							});
							idacard.lock();

							idbcard = new Uploader({
								at: $('.panel-detail #idBCard'),
								value: vm.userlandlord.idBPath
							});
							idbcard.lock();

	                    }else{
	                        alertMsg(r.msg);
	                    }
					}
				});
			},
			show_landlord: function () {
				vm.showPanel = "landlord";
			},
			add_house: function(){
				console.log('**** in add');
				vm.showPanel = "add";
				vm.showlandlord = false;
				vm.userlandlord = {};
				vm.house = {
		            status: "1",
		            cityName: "雄安市",
		            districtName: "雄县",
					rentType: "整租",
					payMode: "一月一付"
				};
	            var hdobj = $('.panel-add .hardwares input[type="checkbox"]');
	            for (var i=0; i<hdobj.length; i++) {
	            	$(hdobj[i]).prop('checked', false);
	            }
	            $('.house-new-imgs').html('');
	            $('.propright-new-imgs').html('');
				imgup_at_add();
				prop_at_add()
				apm_at_add();
			},
			update: function (id) {
				console.log('**** in update, id: ', id);
				vm.userlandlord = {};
				if (!id) {return false;}
	            var url = "../sys/house/detail";
				$.ajax({
					type: 'GET',
				    url: url,
				    data: {houseId: id},
				    success: function(r){
	                    if(r.code == 0){
				            vm.house = r.entity;
				            var hdobj = $('.panel-update .hardwares input[type="checkbox"]');
				            for (var i=0; i<hdobj.length; i++) {
				            	$(hdobj[i]).prop('checked', vm.house.hardware.indexOf( $(hdobj[i]).val() )>=0);
				            }
							imgup_at_update(r.entity.houseImages);
							prop_at_update(r.entity.houseAuthImages);
							apm_at_update(r.entity.children);
							vm.showPanel = "update";

							vm.showlandlord = true;
							vm.userlandlord = r.entity.landlord;
							var idacard, idbcard;
							idacard = new Uploader({
								at: $('.panel-update #idACard'),
								value: vm.userlandlord.idAPath
							});
							idacard.lock();

							idbcard = new Uploader({
								at: $('.panel-update #idBCard'),
								value: vm.userlandlord.idBPath
							});
							idbcard.lock();

	                    }else{
	                        alertMsg(r.msg);
	                    }
					}
				});
			},
			saveOrUpdate: function (event, type) {
				if(vm.house.districtName == null || vm.house.districtName.trim()== ""){
					alertMsg("请选择区县");
					return;
				}
	            if(vm.house.address == null || vm.house.address.trim()== ""){
	                alertMsg("请填写地址信息");
	                return;
	            }
	            if(vm.house.rentType == null || vm.house.rentType.trim()== ""){
	                alertMsg("请输入出租类型");
	                return;
	            }
	            if ("POST" == type && !vm.userlandlord.userName) {
	                alertMsg("请先查询房东信息");
	                return;
	            }

	            var panel = 'PUT'==type ? '.panel-update' : '.panel-add';


	            var childrens = [];
            	for (var i=0; i<$(panel + ' .rooms .room-line').length; i++) {
            		var room = $(panel + ' .rooms .room-line')[i];
            		var obj = {
						id: $(room).find('.room-id').val(),
						door: $(room).find('.room-door').val(),
						direct: $(room).find('.room-direct').val(),
						buildingArea: $(room).find('.room-buildingArea').val(),
						rentalPrice: $(room).find('.room-rentalPrice').val(),
						payMode: $(room).find('.room-payMode').val(),
            		};
            		if (obj.door && obj.direct && obj.buildingArea && obj.rentalPrice && obj.payMode) {
            			childrens.push(obj);
            		} else {
            			if ("合租" == vm.house.rentType) {
	            			alertMsg('请填写完整的房间信息。');
	            			return;
	            		}
            		}
            	}
	            vm.house.children = childrens;


	            var hardwares = [], hwobj = $(panel + ' .hardwares input[type="checkbox"]:checked');
	            for (var i=0; i<hwobj.length; i++) {
	            	hardwares.push($(hwobj[i]).val());
	            }
	            vm.house.hardware = hardwares.join(',');

	            //处理房源图片
	            var houseImages = [];
	            var imageBox;
                if('PUT' == type){
                    imageBox = $('.house-update-imgs');
				}else{
                    imageBox = $('.house-new-imgs');
				}
				var imageChildren = imageBox.children('.file-uploader');
                if(imageChildren){
                	for(var i = 0; i < imageChildren.length; i++){
                		var imageEle = imageChildren[i];
                		var id = imageEle.getAttribute("id");
                		var imageUrl = imageEle.getAttribute("imgUrl");
                		if(imageUrl && imageUrl.indexOf("getfile") > 0){
                			if(id && id.indexOf("-") >= 0){
                				//前端自动生成的id, 非后端传过来的
                                houseImages.push({'imageUrl':imageUrl});
							}else{
                                houseImages.push({'id': id, 'imageUrl':imageUrl});
							}
						}
					}
				}
                vm.house.houseImages = houseImages;
                /*
	            for (var i=0; i<vm.house_add_imgs.length; i++) {
	            	if (vm.house_add_imgs[i].obj.val()) {
	            		var tmp = {'imageUrl': vm.house_add_imgs[i].obj.val()};
	            		houseImages.push(tmp);
	            	}
	            }
	            vm.house.houseImages = houseImages;
	            */

                //处理房源产权图片
	            var houseAuthImages = [];
                var imageAuthBox;
                if('PUT' == type){
                    imageAuthBox = $('.propright-update-imgs');
                }else{
                    imageAuthBox = $('.propright-new-imgs');
                }
                var imageAuthChildren = imageAuthBox.children('.file-uploader');
                if(imageAuthChildren){
                    for(var i = 0; i < imageAuthChildren.length; i++){
                        var imageEle = imageAuthChildren[i];
                        var id = imageEle.getAttribute("id");
                        var imageUrl = imageEle.getAttribute("imgUrl");
                        if(imageUrl && imageUrl.indexOf("getfile") > 0){
                            if(id && id.indexOf("-") >= 0){
                                //前端自动生成的id, 非后端传过来的
                                houseAuthImages.push({'imageUrl':imageUrl});
                            }else{
                                houseAuthImages.push({'id': id, 'imageUrl':imageUrl});
                            }
                        }
                    }
                }
                vm.house.houseAuthImages = houseAuthImages;
                /*
	            for (var i=0; i<vm.propright_add_imgs.length; i++) {
	            	if (vm.propright_add_imgs[i].obj.val()) {
		            	var tmp = {'imageUrl': vm.propright_add_imgs[i].obj.val()};
		            	houseAuthImages.push(tmp);
	         	   }
	        	}
	            vm.house.houseAuthImages = houseAuthImages;
	            */

                //console.log(JSON.stringify(vm.house));

                // 以下不要提交到服务器
	            delete vm.house.houseOperationLogs;
	            delete vm.house.landlord;


	            $('.saveOrUpdate').addClass('layui-btn-disabled');
	            var url = "../sys/house";
				$.ajax({
					type: type,
				    url: url,
				    data: JSON.stringify(vm.house),
				    datatype: 'json',
				    contentType: 'application/json; charset=utf-8',
				    success: function(r){
	                    if(r.code == 0){
	                        $layer.alert(r.msg, {icon: 1}, function(index) {
	                        	vm.showPanel = 'list';
	                        	vm.reload();
	                        	$layer.close(index);
	                        });
	                    }else{
	                        alertMsg(r.msg);
	                    }
					},
					complete: function () {
			            $('.saveOrUpdate').removeClass('layui-btn-disabled');
					}
				});
			},
		    reload: function (event) {
		    	vm.showPanel = 'list';
				var page = $("#jqGrid").jqGrid('getGridParam','page');
				$("#jqGrid").jqGrid('setGridParam',{ 
	                postData:{'serialNum': vm.q.serialNum,
	                	'districtName':vm.q.districtName,
	                	'rentType':vm.q.rentType,
	                	'rentStatus':vm.q.rentStatus},
	                page:page
	            }).trigger("reloadGrid");
			},
			landlord: function () {
				if (!vm.house.ownerPhone) {
					return false;
				}
				var url = '../sys/userLandlord/findByPhone/' + vm.house.ownerPhone;
				$.get(url, function(result) {
					if (result.code == '0') {
						if (result.userlandlord) {
							vm.userlandlord = result.userlandlord;
							vm.showlandlord = true;
							var idacard = new Uploader({
								at: $('.panel-add #idACard'),
								value: vm.userlandlord.idAPath
							});
							var idbcard = new Uploader({
								at: $('.panel-add #idBCard'),
								value: vm.userlandlord.idBPath
							});
						} else {
							alert('未找到房东信息');
						}
					} else {
						alert(result.msg);
					}
				});
				return false;
			}
		}
	});

var imgup_at_add = function () {
	var id, dom, obj;
	id = 'h-' + uuid.n8();
	dom = $('<div class="file-uploader" id="'+id+'" imgUrl="" data-drop="true" data-title="房间照片"></div>');
	$('.house-new-imgs').append(dom);
	obj = new Uploader({parent :$('.house-new-imgs'), at: $('#'+id), success: function(result) {
		if (result.isNew) { imgup_at_add() };
	}});

	//vm.house_add_imgs.push({ id: id, obj: obj })
}

var prop_at_add = function () {
	var id, dom, obj;
	id = 'pr-' + uuid.n8();
	dom = $('<div class="file-uploader" id="'+id+'" imgUrl="" data-drop="true" data-title="产权照片"></div>');
	$('.propright-new-imgs').append(dom);
	obj = new Uploader({parent :$('.propright-new-imgs'), at: $('#'+id), success: function(result) {
		if (result.isNew) { prop_at_add() };
	}});

	//vm.propright_add_imgs.push({ id: id, obj: obj })
}

var imgup_at_update = function (images) {
    //wangyuan; fix bug(修复图片重复出现)
    $('.house-update-imgs').empty();

	for (var i=0; i<images.length; i++) {
        var id;
        if(images[i].id){
        	id = images[i].id;
		}else{
            id = 'h-' + uuid.n8();
		}

		var dom = $('<div class="file-uploader" id="'+id+'" imgUrl="'+images[i].imageUrl+'" data-icon="'+images[i].imageUrl+'" data-drop="true" data-title="房间照片"></div>');
		$('.house-update-imgs').append(dom);
		var obj = new Uploader({parent :$('.house-update-imgs'), at: $('#'+id), success: function(result) {
			if (result.isNew) {
				//imgup_at_add();
                newUploadComp("h-", "房间照片", "house-update-imgs")
			};
		}});

        obj._value = images[i].imageUrl; // 关系到 result.isNew 的判断

        obj._vm.remove.show();
	}

    newUploadComp("h-", "房间照片", "house-update-imgs");
}

//创建新的图片
var newUploadComp = function (idPre, title, parentClass) {
	var id = idPre + uuid.n8();
    var domNew = $('<div class="file-uploader" id="' + id +'" imgUrl="" data-drop="true" data-title="'+ title +'"></div>');
    $('.'+ parentClass +'').append(domNew);
    var objNew = new Uploader({parent :$('.'+ parentClass +''), at: $('#'+id), success: function(result) {
    	if (result.isNew) {
		     newUploadComp(idPre, title, parentClass);
	    };
    }});
}

var prop_at_update = function (images) {
    //wangyuan; fix bug(修复图片重复出现)
    $('.propright-update-imgs').empty();

	for (var i=0; i<images.length; i++) {
        var id;
        if(images[i].id){
            id = images[i].id;
        }else{
            id = 'pr-' + uuid.n8();
        }

		var dom = $('<div class="file-uploader" id="'+id+'"  imgUrl="'+images[i].imageUrl+'" data-icon="'+images[i].imageUrl+'" data-drop="true" data-readonly="true" data-title="产权照片"></div>');
		$('.propright-update-imgs').append(dom);
		var obj = new Uploader({parent :$('.propright-update-imgs'),at: $('#'+id), success: function(result) {
			if (result.isNew) {
				//prop_at_update()
                newUploadComp("pr-", "产权照片", "propright-update-imgs");
			};
		}});

        obj._value = images[i].imageUrl; // 关系到 result.isNew 的判断

        obj._vm.remove.show();
	}

    newUploadComp("pr-", "产权照片", "propright-update-imgs");
}

var imgup_at_detail = function (images) {
    //wangyuan; fix bug(修复图片重复出现)
    $('.house-detail-imgs').empty();

	for (var i=0; i<images.length; i++) {
		var id = 'h-' + uuid.n8();
		var dom = $('<div class="file-uploader" id="'+id+'" data-icon="'+images[i].imageUrl+'" data-readonly="true"" data-title="房间照片"></div>');
		$('.house-detail-imgs').append(dom);
		new Uploader({ at: $('#'+id) })
	}
}

var prop_at_detail = function (images) {
    //wangyuan; fix bug(修复图片重复出现)
    $('.propright-detail-imgs').empty();

	for (var i=0; i<images.length; i++) {
		var id = 'pr-' + uuid.n8();
		var dom = $('<div class="file-uploader" id="'+id+'" data-icon="'+images[i].imageUrl+'" data-readonly="true"" data-title="房间照片"></div>');
		$('.propright-detail-imgs').append(dom);
		new Uploader({ at: $('#'+id) })
	}
}

var apm_at_add = function () {
	$('.room-door').val('');
	$('.room-direct').val('');
	$('.room-buildingArea').val('');
	$('.room-rentalPrice').val('');
	$('.room-payMode').val('');
	$('.rentType-add .rooms .update').remove();
	$('.rentType-add .new-room').off('click').on('click', function () {
		$('.rentType-add .rooms').append(apm_el({}));
		return false;
	})
}

var apm_at_update = function (rooms) {
	$('.room-door').val('');
	$('.room-direct').val('');
	$('.room-buildingArea').val('');
	$('.room-rentalPrice').val('');
	$('.room-payMode').val('');
	$('.rentType-update .rooms .update').remove();
	for (var i=0; i<rooms.length; i++) {
		$('.rentType-update .rooms').append(apm_el({
			value: rooms[i],
			index: i
		}));	
	}
	if (rooms.length == 0) {
		$('.rentType-update .rooms').append(apm_el({
			index: 0
		}));	
	}
	$('.rentType-update .new-room').off('click').on('click', function () {
		$('.rentType-update .rooms').append(apm_el({}));
		return false;
	})
}

var apm_at_detail = function (rooms) {
	$('.room-door').val('');
	$('.room-direct').val('');
	$('.room-buildingArea').val('');
	$('.room-rentalPrice').val('');
	$('.room-payMode').val('');
	$('.rentType-detail .rooms').html('');
	for (var i=0; i<rooms.length; i++) {
		$('.rentType-detail .rooms').append(apm_el({
			readonly: true,
			value: rooms[i]
		}));	
	}
}

var apm_el = function (opt) {
	var tmp = [];
	tmp.push('<div class="room-line row update">');
		tmp.push('<div class="col-md-1 control-label">房间</div>');
			tmp.push('<input class="form-control room-id" type="hidden"/>');
		tmp.push('<div class="col-md-1">');
			tmp.push('<input class="form-control room-door" type="text" placeholder="房间号"/>');
		tmp.push('</div>');
		tmp.push('<div class="col-md-1">');
			tmp.push('<select class="form-control room-direct">');
				tmp.push('<option value="">请选择朝向</option><option>东</option><option>南</option><option>西</option><option>北</option><option>东南</option><option>西南</option><option>东北</option><option>西北</option>');
			tmp.push('</select>');
		tmp.push('</div>');
		tmp.push('<div class="col-md-1">');
			tmp.push('<input class="form-control room-buildingArea" type="number" min="0" placeholder="面积"/>');
		tmp.push('</div>');
		tmp.push('<div class="col-md-1">');
			tmp.push('<input class="form-control room-rentalPrice" type="number" min="0" placeholder="挂牌租金"/>');
		tmp.push('</div>');
		tmp.push('<div class="col-md-1">');
			tmp.push('<select class="form-control room-payMode">');
				tmp.push('<option value="">请选择支付方式</option><option>一月一付</option><option>两月一付</option><option>三月一付</option><option>六月一付</option><option>一年一付</option>');
			tmp.push('</select>');
		tmp.push('</div>');
	if (opt && opt.readonly) {
	} else {
		if (opt.index == 0) {
			tmp.push('	<button class="layui-btn new-room">新增房间</button>');
		} else {
			tmp.push('	<button class="layui-btn layui-btn-danger del-room">删除房间</button>');
		}
	}
	tmp.push('</div>');
	var result = $(tmp.join(''));

	if (opt.value) {
		result.find('.room-id').val(opt.value.id);
		result.find('.room-door').val(opt.value.door);
		result.find('.room-direct').val(opt.value.direct);
		result.find('.room-buildingArea').val(opt.value.buildingArea);
		result.find('.room-rentalPrice').val(opt.value.rentalPrice);
		result.find('.room-payMode').val(opt.value.payMode);
	}
	if (opt.readonly) {
		result.find('.room-door').prop('readonly', true);
		result.find('.room-direct').prop('disabled', true);
		result.find('.room-buildingArea').prop('readonly', true);
		result.find('.room-rentalPrice').prop('readonly', true);
		result.find('.room-payMode').prop('disabled', true);
	}

	result.find('.del-room').on('click', function () {
		$(this).closest('.room-line').remove();
		console.log('delete it!');
		return false;
	})
	return result;
}

// vm.add();


